#!/bin/bash

# Get the sfcbd process first
SFCBD=`ps axo pid,ppid,cmd | grep sfcbd | awk '($2 == 1){print $0}' | head -n 1 | awk '{print $1}'`

if [ -z "$SFCBD" ]
then
    echo "Can not get sfcb daemon"
    exit 1
fi

echo "Get sfcb daemon process id = $SFCBD"

ps axo pid,ppid,pcpu,pmem,size,vsize --sort=size | awk '($2 == "'"$SFCBD"'"){ print $0 }' | sort | while read pid ppid pcpu pmem size vsize
do
    status=`cat /proc/$pid/status | grep "State:" | awk '{print $NF}' | head -n 1`
    realname=`cat /proc/$pid/maps | grep "Provider.so" | awk '{print $NF}' | head -n 1`
    if [ -z $realname ]; then continue; fi
    # echo $size | awk '{printf("%.5sMB\n", $size/1024)}'
    
    echo $pid"  "	$size" KB  "	$vsize" KB  "	$realname   $status
done 

exit 1

ps axo pid,ppid,pcpu,pmem,size,vsize --sort=size 


